package com.zhang.gulimall.search.controller;

import com.zhang.gulimall.search.service.SearchService;
import com.zhang.gulimall.search.vo.SearchParam;
import com.zhang.gulimall.search.vo.MySearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class SearchController {

    @Autowired
    SearchService searchService;

    @GetMapping("/list.html")
    public String indexPage(SearchParam param, Model model, HttpServletRequest request){
        param.setQueryString(request.getQueryString());
        MySearchResult search = searchService.search(param);
        model.addAttribute("result",search);
        return "list";
    }
}
